$(function(){
    //查看联系方式登录按钮
    $(".companylogin").click(function(){
        layer.open({
            content: '企业登录后才能查看，现在登录吗？'
            ,btn: ['登录', '稍等一会']
            ,yes: function(index){
                location.href = "/mobile/company/login";
            }
        });
    });
    //面试邀请登录按钮
    $(".companylogin2").click(function(){
        layer.open({
            content: '企业登录后才能邀请，现在登录吗？'
            ,btn: ['登录', '稍等一会']
            ,yes: function(index){
                location.href = "/mobile/company/login";
            }
        });
    });
    //绑定面试邀请框
    $(".button2").click(function(){
        $.post('/mobile/company/inviteinterview',{ '_token': _token,'resumeId': resumeId },function (data) {
            if(data.status == '2'){
                layerMsg('亲，您的会员已到期或简历数已用尽！',2);
                return false;
            }else if(data.status == '3'){
                layerMsg('亲，您还未发布工作岗位！',2);
                return false;
            }else if(data.status == '1'){
                inviteTitle = data.inviteTitle;


                var str = '';
                str+='<div class="select_con">';
                str+='<div class="select_header">';
                str+='<a class="close"></a>';
                str+='<div class="title">邀请面试</div>';
                str+='</div>';

                str+='<div class="fill" id="fill" style="margin-top: 1rem">';
                str+='<div class="form_info" id="form_info">';
                str+='<form action=""  onsubmit="return checkInterview(\'#interviewForm\')" method="post" id="interviewForm" name="interviewForm">';
                str+='<input type="hidden" name="_token"  value="'+_token+'">';

                str+='<input type="hidden" name="resumeId" id="resumeId"  value="'+resumeId+'">';
                str+='<dl class="arrow" id="jobId_select">';
                str+='<input type="hidden" name="jobId" value="" id="jobId" />';
                str+='<dt>面试职位<span class="asterisk">*</span></dt>';
                str+='<dd><span class="select_text">请选择面试职位</span></dd>';
                str+='</dl>';

                str+='<dl>';
                str+='<dt>面试时间<span class="asterisk">*</span></dt>';
                str+='<dd><input type="datetime-local" name="inpstart" id="inpstart"  value="'+interViewTime+'" step=1 placeholder="请选择面试时间" autocomplete="off"></dd>';
                str+='</dl>';

                str+='<dl class="arrow" id="jobnote_description">';
                str+='<dt>相关备注</dt>';
                str+='<dd>';
                str+='<textarea name="jobnote" id="jobnote" style="display: none;"></textarea>';
                str+='<span class="select_text">请输入相关备注</span>';
                str+='</dd>';
                str+='</dl>';

                str+='<div class="form_sub"><input type="submit" value="发送邀请"></div>';
                str+='</form>';
                str+='</div>';
                str+='</div>';

                str+='</div>';
                //追击添加的内容
                $('body').append(str);
                $('.select_con').animate({
                    left:'0',
                    'animation':'select_start 0.4s 0s ease',
                    'display':'block'
                }, 400);
                //关闭加载层 清除select
                $('.select_con').find('.close').click(function(){
                    $('.select_con').animate({
                        'left':'7.5rem',
                        'animation':'select_end .4s 0s ease',
                        'display':'block'
                    }, 400 ,function(){
                        $('.select_con').remove();
                    });
                });

                //面试职位
                $('.select_con').find("#jobId_select").select({
                    select_title:'面试职位',
                    hidden: '#jobId',
                    opt_data:inviteTitle
                });
                //相关备注
                $('.select_con').find("#jobnote_description").textarea({
                    text_title:'相关备注',
                    hidden: '#jobnote'
                });

            }
        });
    });
});

/**
 * 检查面试邀请
 * @param oForm
 * @returns {boolean}
 */
function checkInterview(oForm){
    if ($(oForm).find('#jobId').val() == '') {
        layerMsg('请选择面试职位!', 2);
        return false;
    }
    var inpstart = str_trim($(oForm).find('#inpstart').val());
    if (inpstart == '') {
        layerMsg('请选择面试时间!', 2);
        $(oForm).find('#inpstart').focus();
        $(oForm).find('#inpstart').val(inpstart);
        return false;
    }
    var queryString = $(oForm).serialize();
    $.ajax({
        url: "/company/interviewnote",
        dataType: "json",
        data: queryString,
        type: "POST",
        beforeSend: function () {
            $(oForm).find("input[type='submit']").val('请稍候...');
            $(oForm).find("input[type='submit']").attr('disabled', true);
        },
        success: function (data) {
            layerMsg(data.msg,2);
            $(oForm).find("input[type='submit']").val('发送邀请');
            $(oForm).find("input[type='submit']").removeAttr('disabled');
            $('.select_con').animate({
                'left':'7.5rem',
                'animation':'select_end .4s 0s ease',
                'display':'block'
            }, 400 ,function(){
                $('.select_con').remove();
            });
            showContact();
            return false;
        },
        error: function (data) {
            var msgErr='';
            var errors = $.parseJSON(data.responseText);
            $.each(errors, function(index, value) {
                msgErr += "<p style='line-height: .4rem; width: 100%'>"+ value+";</p>";
            });
            layerMsg(msgErr,2);
            $(oForm).find("input[type='submit']").val('发送邀请');
            $(oForm).find("input[type='submit']").removeAttr('disabled');
            return false;
        },
        complete: function () {
        }
    });
    return false;
}